home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / telecomm / uemlsrc.arc / termio.c < prev    next >
C/C++ Source or Header  |  1987-08-24  |  21KB  |  602 lines

  1. /*
  2.  * The functions in this file
  3.  * negotiate with the operating system
  4.  * for characters, and write characters in
  5.  * a barely buffered fashion on the display.
  6.  * All operating systems.
  7.  */
  8. #include        <stdio.h>
  9. #include        <ctype.h>
  10. #include        <osbind.h>
  11. #include        "ed.h"
  12.  
  13. #if ST
  14. #define BORDER  0
  15. #define CURSOR  1
  16. #define DESK    2
  17. #define LETTER  3
  18. #define BLACK   0
  19. #define WHITE   0x777
  20. #define COBALT  0x007
  21. #define TEAL    0x055
  22. #define GREEN   0x070
  23. #define GREY    0x555
  24. #define RED     0x700
  25. #define MAGENTA 0x707
  26. #define YELLOW  0x770
  27. /* the first four are the saved values */
  28. int     bordcol;        /* #0   */
  29. int     curscol;        /* #1   */
  30. int     deskcol;        /* #2   */
  31. int     letcol;         /* #3   */
  32. /* these are the internal values */
  33. int     bcolor;         /* #0   */
  34. int     ccolor;         /* #1   */
  35. int     dcolor;         /* #2   */
  36. int     lcolor;         /* #3   */
  37. char    *colornames[4] = {"Magenta","Magenta","Magenta","Magenta"};
  38. #endif
  39.  
  40. #if     VMS
  41. #include        <stsdef.h>
  42. #include        <ssdef.h>
  43. #include        <descrip.h>
  44. #include        <iodef.h>
  45. #include        <ttdef.h>
  46.  
  47. #define NIBUF   128                     /* Input  buffer size           */
  48. #define NOBUF   1024                    /* MM says bug buffers win!     */
  49. #define EFN     0                       /* Event flag                   */
  50.  
  51. char    obuf[NOBUF];                    /* Output buffer                */
  52. int     nobuf;                          /* # of bytes in above          */
  53. char    ibuf[NIBUF];                    /* Input buffer                 */
  54. int     nibuf;                          /* # of bytes in above          */
  55. int     ibufi;                          /* Read index                   */
  56. int     oldmode[2];                     /* Old TTY mode bits            */
  57. int     newmode[2];                     /* New TTY mode bits            */
  58. short   iochan;                         /* TTY I/O channel              */
  59. #endif
  60.  
  61. #if     MSDOS
  62. #include        <dos.h>
  63. #endif
  64.  
  65. #if V7
  66. #include        <sgtty.h>               /* for stty/gtty functions */
  67. struct  sgttyb  ostate;                 /* saved tty state */
  68. struct  sgttyb  nstate;                 /* values for editor mode */
  69. #endif
  70.  
  71. /*
  72.  * This function is called once
  73.  * to set up the terminal device streams.
  74.  * On VMS, it translates SYS$INPUT until it
  75.  * finds the terminal, then assigns a channel to it
  76.  * and sets it raw. On CPM it is a no-op.  On the ST
  77.  * it is called to update the screen color and every
  78.  * time we return from spawn or the term mode.
  79.  */
  80. ttopen()
  81. {
  82. #if     VMS
  83.         struct  dsc$descriptor  idsc;
  84.         struct  dsc$descriptor  odsc;
  85.         char    oname[40];
  86.         int     iosb[2];
  87.         int     status;
  88.  
  89.         odsc.dsc$a_pointer = "SYS$INPUT";
  90.         odsc.dsc$w_length  = strlen(odsc.dsc$a_pointer);
  91.         odsc.dsc$b_dtype   = DSC$K_DTYPE_T;
  92.         odsc.dsc$b_class   = DSC$K_CLASS_S;
  93.         idsc.dsc$b_dtype   = DSC$K_DTYPE_T;
  94.         idsc.dsc$b_class   = DSC$K_CLASS_S;
  95.         do {
  96.                 idsc.dsc$a_pointer = odsc.dsc$a_pointer;
  97.                 idsc.dsc$w_length  = odsc.dsc$w_length;
  98.                 odsc.dsc$a_pointer = &oname[0];
  99.                 odsc.dsc$w_length  = sizeof(oname);
  100.                 status = LIB$SYS_TRNLOG(&idsc, &odsc.dsc$w_length, &odsc);
  101.                 if (status!=SS$_NORMAL && status!=SS$_NOTRAN)
  102.                         exit(status);
  103.                 if (oname[0] == 0x1B) {
  104.                         odsc.dsc$a_pointer += 4;
  105.                         odsc.dsc$w_length  -= 4;
  106.                 }
  107.         } while (status == SS$_NORMAL);
  108.         status = SYS$ASSIGN(&odsc, &iochan, 0, 0);
  109.         if (status != SS$_NORMAL)
  110.                 exit(status);
  111.         status = SYS$QIOW(EFN, iochan, IO$_SENSEMODE, iosb, 0, 0,
  112.                           oldmode, sizeof(oldmode), 0, 0, 0, 0);
  113.         if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL)
  114.                 exit(status);
  115.         newmode[0] = oldmode[0];
  116.         newmode[1] = oldmode[1] | TT$M_PASSALL | TT$M_NOECHO;
  117.         status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0,
  118.                           newmode, sizeof(newmode), 0, 0, 0, 0);
  119.         if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL)
  120.                 exit(status);
  121. #endif
  122. #if     ST
  123.         static char first = TRUE;
  124.         char colornm[80];
  125.         register int i;
  126.         char temp[40];
  127.  
  128.         if (first)
  129.                 {
  130.                 i = 0;
  131.                 Crawio(0x1b);   /* clear and home */
  132.                 Crawio('E');
  133.                 bcolor = WHITE; /* border */
  134.                 strcpy(colorname[i++],"White");
  135.                 if(!alias(temp,"border"))
  136.                         insalias("border","white");
  137.                 ccolor = WHITE; /* cursor */
  138.                 strcpy(colorname[i++],"White");
  139.                 if(!alias(temp,"cursor"))
  140.                         insalias("cursor","white");
  141.                 dcolor = BLACK; /* screen (desk) */
  142.                 strcpy(colorname[i++],"Black");
  143.                 if(!alias(temp,"desk"))
  144.                         insalias("desk","black");
  145.                 lcolor = WHITE; /* letters */
  146.                 strcpy(colorname[i++],"White");
  147.                 if(!alias(temp,"letter"))
  148.                         insalias("letter","white");
  149.                 first = FALSE;
  150.                 }
  151.         /* check for user preferences */
  152.         i = 0;
  153.         if (alias(colornm,"border"))
  154.                 {
  155.                 if (strcmp(colornm,"red")==NULL)
  156.                         {
  157.                         bcolor = RED;
  158.                         strcpy(colornames[0],"Red");
  159.                         }
  160.                 else if (strcmp(colornm,"black")==NULL)
  161.                         {
  162.                         bcolor = BLACK;
  163.                         strcpy(colornames[0],"Black");
  164.                         }
  165.                 else if (strcmp(colornm,"white")==NULL)
  166.                         {
  167.                         bcolor = WHITE;
  168.                         strcpy(colornames[0],"White");
  169.                         }
  170.                 else if (strcmp(colornm,"cobalt")==NULL)
  171.                         {
  172.                         bcolor = COBALT;
  173.                         strcpy(colornames[0],"Cobalt");
  174.                         }
  175.                 else if (strcmp(colornm,"green")==NULL)
  176.                         {
  177.                         bcolor = GREEN;
  178.                         strcpy(colornames[0],"Green");
  179.                         }
  180.                 else if (strcmp(colornm,"magenta")==NULL)
  181.                         {
  182.                         bcolor = MAGENTA;
  183.                         strcpy(colornames[0],"Magenta");
  184.                         }
  185.                 else if (strcmp(colornm,"yellow")==NULL)
  186.                         {
  187.                         bcolor = YELLOW;
  188.                         strcpy(colornames[0],"Yellow");
  189.                         }
  190.                 else if (strcmp(colornm,"grey")==NULL)
  191.                         {
  192.                         bcolor = GREY;
  193.                         strcpy(colornames[0],"Grey");
  194.                         }
  195.                 else if (strcmp(colornm,"teal")==NULL)
  196.                         {
  197.                         bcolor = TEAL;
  198.                         strcpy(colornames[0],"Teal");
  199.                         }
  200.                 }
  201.         if (alias(colornm,"cursor"))
  202.                 {
  203.                 if (strcmp(colornm,"red")==NULL)
  204.                         {
  205.                         ccolor = RED;
  206.                         strcpy(colornames[1],"Red");
  207.                         }
  208.                 else if (strcmp(colornm,"black")==NULL)
  209.                         {
  210.                         ccolor = BLACK;
  211.                         strcpy(colornames[1],"Black");
  212.                         }
  213.                 else if (strcmp(colornm,"white")==NULL)
  214.                         {
  215.                         ccolor = WHITE;
  216.                         strcpy(colornames[1],"White");
  217.                         }
  218.                 else if (strcmp(colornm,"cobalt")==NULL)
  219.                         {
  220.                         ccolor = COBALT;
  221.                         strcpy(colornames[1],"Cobalt");
  222.                         }
  223.                 else if (s